﻿using DNFImagePacks2Manager.Helpers;
using Microsoft.UI.Xaml.Controls;
using System;
using System.IO;

namespace DNFImagePacks2Manager.Models
{
    class BKItemOfficial(string path, string display) : BKItemSingle(display + ".bk2")
    {

        public string FilePath = path;
        public override string DisplayName => Name;

        public override string BKFile => Path.Combine(LocalStorageHelper.GetBKOfficialPath(), FilePath);

        public bool Install(Page page, string name)
        {
            try
            {
                string file = BKFile;
                string installName = name + Suffix;
                string installFile = Path.Combine(BKHelper.GetSingleFolder(), installName);
                if (File.Exists(file))
                {
                    if (File.Exists(installFile))
                    {
                        DialogHelper.ShowErrorMessage(page, "安装失败: 目标文件已存在");
                    }
                    else
                    {
                        File.Copy(file, installFile);
                        DialogHelper.ShowSuccessMessage(page, "安装完成");
                        return true;
                    }
                }
                else
                {
                    DialogHelper.ShowErrorMessage(page, "安装失败: 找不到文件");
                }
            }
            catch (Exception ex)
            {
                DialogHelper.ShowErrorMessage(page, $"安装失败: {ex.Message}");
            }
            return false;
        }

        public override void Apply(Page page)
        {
            return;
        }

        public override void Edit(Page page)
        {
            return;
        }

        public override bool Delete(Page page)
        {
            return false;
        }

        public override bool Rename(Page page, string name)
        {
            return false;
        }
    }
}
